package com.yingxue.lesson.utils;

import com.github.pagehelper.Page;
import com.yingxue.lesson.vo.resp.PageVO;

import java.util.List;

/**
 * @author chahua
 * @date 2022/4/5 15:58
 **/
public class PageUtils {

    private PageUtils(){}

    public static <T> PageVO<T> getPageVO(List<T> list){

        PageVO<T> result=new PageVO<>();

        if(list instanceof Page){
            Page<T> page= (Page<T>) list;
            result.setTotalRows(page.getTotal());
            result.setTotalPages(page.getPages());
            result.setPageNum(page.getPageNum());
            result.setCurPageSize(page.getPageSize());
            result.setPageSize(page.size());
            result.setList(page.getResult());
        }

        return result;
    }

}
